#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <gtk/gtk.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include "callbacks.h"
#include "interface.h"
#include "support.h"
#include "menu.h"
#include "gestion_capteurs.h"
#include "Personnel.h"
#include "Patient.h"
#include"analyse.h"

void on_button1_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget * window2;
	GtkWidget * window1;
        window1 = lookup_widget(objet_graphique,"window1");
        gtk_widget_hide(window1);
	window2 = create_window2();
	gtk_widget_set_size_request (window2, 400, 700);
	gtk_widget_show (window2);
}



void on_button2_clicked(GtkWidget *objet_graphique, gpointer user_data)
{

	GtkWidget * window3;
	GtkWidget * window1;
        window1 = lookup_widget(objet_graphique,"window1");
        gtk_widget_hide(window1);
	window3 = create_window3();
	gtk_widget_set_size_request (window3, 1150, 700);
	gtk_widget_show (window3);
	personnel p;
	char fichier[] = "fichierpersonnel.txt";
	GtkWidget * label14;
	char tmp[100000]="";
	char Buf[1000]="";
	char Buf0[100]= " ID:";
	char Buf1[100]= " nom:";
	char Buf2[100]= " prenom:";
	char Buf3[100]= " cin:";
	char Buf4[100]= " age:";
	char Buf5[100]= " sexe:";
	char Buf6[100]= " num_tel:";
	char Buf7[100]= " adresse:";
	char Buf8[100]= " poste:";
	char Buf9[100]= " date d'embauche:";
	char Buf10[100]= "/";
	char Buf11[100]= "/";
	FILE*f;

f=fopen(fichier,"rb");
if(f!=NULL)
{
p.ID=0;
strcpy (p.nom," " ) ;
strcpy(p.prenom," ");
p.cin=0;
p.age=0;
strcpy(p.sexe," ");
p.numerotelephone=0;
strcpy(p.adresse," ");
p.datedembauche.jour=0;
p.datedembauche.mois=0;
p.datedembauche.annee=0;
   fread(&p,sizeof(personnel),1,f);
   do
  {
   	sprintf(Buf, "%s %d %s %s %s %s %s %ld %s %d %s %s %s %ld %s %s %s %s %s %d  %s %d  %s %d ", Buf0, p.ID, Buf1,p.nom, Buf2, p.prenom, Buf3, p.cin, Buf4, p.age, Buf5, p.sexe, Buf6, p.numerotelephone, Buf7,p.adresse, Buf8, p.poste, Buf9, p.datedembauche.jour, Buf10,p.datedembauche.mois,Buf11, p.datedembauche.annee );
 strcat(tmp,Buf);
strcat(tmp,"\n\n");
 }
   while(((fread(&p,sizeof(personnel),1,f))!=0)&&(feof(f)!=1));
	label14= lookup_widget(GTK_WIDGET(window3), "label14");
gtk_label_set_text(GTK_LABEL(label14),tmp);


}

fclose(f);
}



void on_button3_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget * window4;
	GtkWidget * window1;
        window1 = lookup_widget(objet_graphique,"window1");
        gtk_widget_hide(window1);
	window4 = create_window4();
	gtk_widget_set_size_request (window4, 1000, 700);
	gtk_widget_show (window4);
}



void on_button4_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget * window5;
	GtkWidget * window1;
        window1 = lookup_widget(objet_graphique,"window1");
        gtk_widget_hide(window1);
	window5 = create_window5();
	gtk_widget_set_size_request (window5, 400, 500);
	gtk_widget_show (window5);
}



void on_button5_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget * window6;
	GtkWidget * window1;
        window1 = lookup_widget(objet_graphique,"window1");
        gtk_widget_hide(window1);
	window6 = create_window6();
	gtk_widget_set_size_request (window6, 500, 600);
	gtk_widget_show (window6);
}



void on_button6_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget * window7;
	GtkWidget * window1;
        window1 = lookup_widget(objet_graphique,"window1");
        gtk_widget_hide(window1);
	window7 = create_window7();
	gtk_widget_show (window7);
	char fichier[] = "fichierpersonnel.txt";
	char Buf0[100];
	GtkWidget * label36;
	initpersonnels(fichier);
	label36= lookup_widget(objet_graphique, "label36");
	sprintf (Buf0, "Personnels initialisés");
	gtk_label_set_text(GTK_LABEL(label36), Buf0);
}



void on_button7_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window8;
	GtkWidget * window1;
        window1 = lookup_widget(objet_graphique,"window1");
        gtk_widget_hide(window1);
	window8 = create_window8();
	gtk_widget_set_size_request (window8, 1100, 700);
	gtk_widget_show (window8);
	personnel p;
	char tmp2[] = "tmp2.txt";
	GtkWidget * label38;

	char tmp[1000000]="";
	char Buf[1000]="";
	char Buf0[100]= " ID:";
	char Buf1[100]= " nom:";
	char Buf2[100]= " prenom:";
	char Buf3[100]= " cin:";
	char Buf4[100]= " age:";
	char Buf5[100]= " sexe:";
	char Buf6[100]= " num_tel:";
	char Buf7[100]= " adresse:";
	char Buf8[100]= " poste:";
	char Buf9[100]= " date d'embauche:";
	char Buf10[100]= "/";
	char Buf11[100]= "/";
	FILE*f;

f=fopen(tmp2,"rb");
if(f!=NULL)
{
p.ID=0;
strcpy (p.nom," " ) ;
strcpy(p.prenom," ");
p.cin=0;
p.age=0;
strcpy(p.sexe," ");
p.numerotelephone=0;
strcpy(p.adresse," ");
p.datedembauche.jour=0;
p.datedembauche.mois=0;
p.datedembauche.annee=0;
   fread(&p,sizeof(personnel),1,f);
   do
  {
   	sprintf(Buf, "%s %d %s %s %s %s %s %ld %s %d %s %s %s %ld  %s %s %s %s %s %d %s %d %s %d ", Buf0, p.ID, Buf1,p.nom, Buf2, p.prenom, Buf3, p.cin, Buf4, p.age, Buf5, p.sexe, Buf6, p.numerotelephone, Buf7,p.adresse, Buf8, p.poste, Buf9, p.datedembauche.jour, Buf10,p.datedembauche.mois,Buf11, p.datedembauche.annee );
 strcat(tmp,Buf);
strcat(tmp,"\n\n");
 }
   while(((fread(&p,sizeof(personnel),1,f))!=0)&&(feof(f)!=1));
   label38= lookup_widget(GTK_WIDGET(window8), "label38");
   gtk_label_set_text(GTK_LABEL(label38),tmp);}

fclose(f);

}



void on_button8_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window0;
	GtkWidget * window1;
        window1 = lookup_widget(objet_graphique,"window1");
        gtk_widget_hide(window1);
	window0 = create_window0();
	gtk_widget_set_size_request (window0, 400, 600);
	gtk_widget_show (window0);
}




void on_button10_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	GtkWidget * window2;
        window2 = lookup_widget(objet_graphique,"window2");
        gtk_widget_hide(window2);
	window1 = create_window1();
	gtk_widget_set_size_request (window1, 400, 600);
	gtk_widget_show (window1);
}

void on_button9_clicked(GtkWidget *objet_graphique, gpointer user_data)
{	personnel p;
	char fichier[] = "fichierpersonnel.txt";
	FILE *y;
	FILE *f;
	int ID;
	int cin;
	int age;
	int numero;
	char Buf1[20]= " ";
	char Buf2[20]= " ";
	char Buf3[20]= " ";
	char Buf4[20]= " ";
	char tmp2[] = "tmp2.txt";
	int ccin=0;
	int l=0;
	int res,res1,res2,res3;
	int rescin=0;
	int res4=0,res5=0,res6=0,res7=0,res8=0;
	GtkWidget *entry1;
	GtkWidget *entry2;
	GtkWidget *entry3;
	GtkWidget *entry4;
	GtkWidget *entry5;
	GtkWidget * label152;
	GtkWidget * label153;
	GtkWidget * label154;
	GtkWidget * label155;

	GtkWidget *entry7;

	GtkWidget *entry35;
	GtkWidget *combobox1;
	GtkWidget *combobox2;	
	GtkCalendar *calendar1;
	

	entry1 = lookup_widget(objet_graphique, "entry1");
	entry2 = lookup_widget(objet_graphique, "entry2");
	entry3 = lookup_widget(objet_graphique, "entry3");
	entry4 = lookup_widget(objet_graphique, "entry4");
	entry5 = lookup_widget(objet_graphique, "entry5");
	entry7 = lookup_widget(objet_graphique, "entry7");
	label152= lookup_widget(objet_graphique, "label152");
	label153= lookup_widget(objet_graphique, "label153");
	label154= lookup_widget(objet_graphique, "label154");
	label155= lookup_widget(objet_graphique, "label155");
	entry35 = lookup_widget(objet_graphique, "entry35");
	combobox1 = lookup_widget(objet_graphique, "combobox1");
	combobox2 = lookup_widget(objet_graphique, "combobox2");
	calendar1 = lookup_widget(objet_graphique, "calendar1");
	sprintf(Buf1,"");
	gtk_label_set_text(GTK_LABEL(label152), Buf1);
	sprintf(Buf2,"");
	gtk_label_set_text(GTK_LABEL(label153), Buf2);
	sprintf(Buf3,"");
	gtk_label_set_text(GTK_LABEL(label154), Buf3);
	sprintf(Buf4,"");
	gtk_label_set_text(GTK_LABEL(label155), Buf4);

res=0;
res1=0;
res2=0;
res3=0;
ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry1)));
l=longueurper(ID);
y=fopen("tmp2.txt","a+");
	if (y!=NULL){
  		while((fread(&p,sizeof(personnel),1,y)!=0) && (res1==0))
		{
		if(ID==p.ID)
		res1=1;
 		}
	}
f=fopen(fichier,"rb");
  if (f!=NULL){
  while((fread(&p,sizeof(personnel),1,f)!=0) && (res==0))
	{
	if(ID==p.ID)
	res=1;
 	}
  }if((ID<0) || (l!=5)){
res3=1;
}
if((res==0)&&(res1==0)&&(res3==0)){
res2=1;}

cin = atoi(gtk_entry_get_text(GTK_ENTRY(entry4)));

  f=fopen("fichierpersonnel","a");
  if (f!=NULL)
	{
         while((fread(&p,sizeof(personnel),1,f)!=0) && (res5==0))
 	    {
	      if(cin==p.cin)
	       {res5=1;}
 	    }
 	}
  y=fopen("tmp2","a");
  if ((y!=NULL) )

	{
         while((fread(&p,sizeof(personnel),1,y)!=0) && (res6==0))
 	    {
	      if(cin==p.cin)
	       {res6=1;}
 	    }
 	}
if( (res5==0) && (res6==0))
{res4=1;}
l=longueurper(cin);
if ((res4==1)&& (l==8))
{rescin=1;}

age = atoi(gtk_entry_get_text(GTK_ENTRY(entry5)));
if ((age>0)&&(age<110))
{
res7=1;
}





numero = atoi(gtk_entry_get_text(GTK_ENTRY(entry7)));
l=longueurper(numero);
if(l==8){
res8=1;}

if(res2==0){

	sprintf(Buf1,"ERREUR");
	gtk_label_set_text(GTK_LABEL(label152), Buf1);
}
if(rescin==0){

	sprintf(Buf2,"ERREUR");
	gtk_label_set_text(GTK_LABEL(label153), Buf2);
}
if(res7==0){

	sprintf(Buf3,"ERREUR");
	gtk_label_set_text(GTK_LABEL(label154), Buf3);
}
if(res8==0){

	sprintf(Buf4,"ERREUR");
	gtk_label_set_text(GTK_LABEL(label155), Buf4);
}


if((res2==1)&&(rescin==1)&&(res7==1)&&(res8==1)){

p.ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry1)));
strcpy(p.nom, gtk_entry_get_text(GTK_ENTRY(entry2)));
strcpy(p.prenom, gtk_entry_get_text(GTK_ENTRY(entry3)));
p.cin = atoi(gtk_entry_get_text(GTK_ENTRY(entry4)));
p.age = atoi(gtk_entry_get_text(GTK_ENTRY(entry5)));
strcpy(p.sexe, gtk_combo_box_get_active_text(GTK_COMBO_BOX(combobox1)));
p.numerotelephone = atoi(gtk_entry_get_text(GTK_ENTRY(entry7)));
strcpy(p.adresse, gtk_entry_get_text(GTK_ENTRY(entry35)));
strcpy(p.poste, gtk_combo_box_get_active_text(GTK_COMBO_BOX(combobox2)));
gtk_calendar_get_date (calendar1,&p.datedembauche.annee,&p.datedembauche.mois,&p.datedembauche.jour);
p.datedembauche.mois= p.datedembauche.mois+1;

	enregistrerpersonnel(fichier,&p);

	GtkWidget *window1;
	GtkWidget * window2;
        window2 = lookup_widget(objet_graphique,"window2");
        gtk_widget_hide(window2);
	window1 = create_window1();
	gtk_widget_set_size_request (window1, 1200, 700);
	gtk_widget_show (window1);
}

}

void on_button11_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	GtkWidget * window3;
        window3 = lookup_widget(objet_graphique,"window3");
        gtk_widget_hide(window3);
	window1 = create_window1();
	gtk_widget_set_size_request (window1, 400, 600);
	gtk_widget_show (window1);
}



void on_button12_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	personnel p;
	char fichier[] = "fichierpersonnel.txt";
	int ID;
	char nom[20];
	int res=0;
	char Buf20[1500]="";
	char Buf0[100]= " ID:";
	char Buf1[100]= " nom:";
	char Buf2[100]= " prenom:";
	char Buf3[100]= " cin:";
	char Buf4[100]= " age:";
	char Buf5[100]= " sexe:";
	char Buf6[100]= " num_tel:";
	char Buf7[100]= " adresse:";
	char Buf8[100]= " poste:";
	char Buf9[100]= " date d'embauche:";
	char Buf10[100]= "/";
	char Buf11[100]= "/";
	char Buf12[100]= " ";
	FILE *f;

	GtkWidget *entry8;
	GtkWidget *entry9;
	GtkWidget * label18;
	GtkWidget * label19;
	entry8 = lookup_widget(objet_graphique, "entry8");
	entry9 = lookup_widget(objet_graphique, "entry9");
	label18= lookup_widget(objet_graphique, "label18");

	strcpy(nom, gtk_entry_get_text(GTK_ENTRY(entry8)));
	ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry9)));


p.ID=0;
strcpy (p.nom," " ) ;
strcpy(p.prenom," ");
p.cin=0;
p.age=0;
strcpy(p.sexe," ");
p.numerotelephone=0;
strcpy(p.adresse," ");
p.datedembauche.jour=0;
p.datedembauche.mois=0;
p.datedembauche.annee=0;
 
  f=fopen(fichier,"rb");
  if (f!=NULL){



  		while(fread(&p,sizeof(personnel),1,f)!=0 && res==0)
			{
			if((strcmp(p.nom,nom)==0)&&(ID==p.ID))
				{res=1;
				break;}
			 }
    		}

if (res==1)
	{sprintf(Buf12,"Le personnel %s existe \n",nom);
	gtk_label_set_text(GTK_LABEL(label18), Buf12);

  	sprintf(Buf20, "%s %d %s %s %s %s %s %ld %s %d %s %s %s %ld %s %s %s %s %s %d  %s %d  %s %d ", Buf0, p.ID, Buf1,p.nom, Buf2, p.prenom, Buf3, p.cin, Buf4, p.age, Buf5, p.sexe, Buf6, p.numerotelephone, Buf7,p.adresse, Buf8, p.poste, Buf9, p.datedembauche.jour, Buf10,p.datedembauche.mois,Buf11, p.datedembauche.annee );

label19= lookup_widget(objet_graphique, "label19");
gtk_label_set_text(GTK_LABEL(label19), Buf20);
fclose(f);
	}
	else {sprintf(Buf12,"Le personnel %s n'existe pas \n",nom);
		gtk_label_set_text(GTK_LABEL(label18), Buf12);}
}



void on_button13_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	GtkWidget * window4;
        window4 = lookup_widget(objet_graphique,"window4");
        gtk_widget_hide(window4);
	window1 = create_window1();
    gtk_widget_set_size_request (window1, 400, 600);
	gtk_widget_show (window1);
}



void on_button14_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *entry40;
	GtkWidget * label22;
	GtkWidget *window1;
	GtkWidget * window5;
	personnel p;
	int ID;
	char fichier[] = "fichierpersonnel.txt";
	char Buf0[1000];
	int res=0;
	entry40 = lookup_widget(objet_graphique, "entry40");
	ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry40)));

FILE *f;
 
  f=fopen(fichier,"rb");
  if (f!=NULL){
  		while((fread(&p,sizeof(personnel),1,f)!=0) && (res==0))
			{
			if(ID==p.ID)
				{res=1;}
			 }
    		}
fclose(f);

	if (res==0)
{
	label22= lookup_widget(objet_graphique, "label22");
	sprintf(Buf0,"Ce personnel n'existe pas \n");
	gtk_label_set_text(GTK_LABEL(label22), Buf0);}

else {
	supprimerpersonnel(fichier,ID);
	/*label22= lookup_widget(GTK_WIDGET(window5), "label22");
	sprintf(Buf0,"Le personnel a été supprimé");
	gtk_label_set_text(GTK_LABEL(label22), Buf0);*/
	window5 = lookup_widget(objet_graphique,"window5");
        gtk_widget_hide(window5);
	window1 = create_window1();
	gtk_widget_set_size_request (window1, 400, 600);
	gtk_widget_show (window1);}

}



void on_button15_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	GtkWidget * window5;
        window5 = lookup_widget(objet_graphique,"window5");
        gtk_widget_hide(window5);
	window1 = create_window1();
	gtk_widget_set_size_request (window1, 400, 600);
	gtk_widget_show (window1);
}



void on_button16_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	personnel per;
	FILE *y;
	FILE *t;
	FILE *f;
	personnel p;
	char fichier[] = "fichierpersonnel.txt";
	char tmp2[] = "tmp2.txt";
	int valeur;
	int ccin=0;
	int testj=0;
	int l=0;
	int l2=0;
	int res,res1,res2,res3;
	char chsexe1[20]= "masculin";
	char chsexe2[20]= "feminin";
	char chposte1[20]= "medecin";
	char chposte2[20]= "infirmier";
	int ID;
	res=0;
	int ID5;

	GtkWidget *entry12;
	GtkWidget *entry14;
	GtkWidget *entry15;
	GtkWidget *entry16;
	GtkWidget *entry17;
	GtkWidget *entry18;
	GtkWidget *entry27;
	GtkWidget *entry28;
	GtkWidget *entry29;
	GtkWidget *entry30;
	GtkWidget *entry31;
	GtkWidget *entry32;
	GtkWidget *entry33;

	entry12 = lookup_widget(objet_graphique, "entry12");
	entry14 = lookup_widget(objet_graphique, "entry14");
	entry15 = lookup_widget(objet_graphique, "entry15");
	entry16 = lookup_widget(objet_graphique, "entry16");
	entry17 = lookup_widget(objet_graphique, "entry17");
	entry18 = lookup_widget(objet_graphique, "entry18");
	entry27 = lookup_widget(objet_graphique, "entry27");
	entry28 = lookup_widget(objet_graphique, "entry28");
	entry29 = lookup_widget(objet_graphique, "entry29");
	entry30 = lookup_widget(objet_graphique, "entry30");
	entry31 =lookup_widget(objet_graphique, "entry31");
	entry32= lookup_widget(objet_graphique, "entry32");
	entry33= lookup_widget(objet_graphique, "entry33");

do {
res=0;
res1=0;
res2=0;
res3=0;
p.ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry14)));
l=longueurper(per.ID);
y=fopen("tmp2.txt","a+");
	if (y!=NULL){
  		while(fread(&p,sizeof(personnel),1,y)!=0 && res1==0)
		{
		if(per.ID==p.ID)
		res1=1;
 		}
	}
f=fopen(fichier,"rb");
  if (f!=NULL){
  while(fread(&p,sizeof(personnel),1,f)!=0 && res==0)
	{
	if(per.ID==p.ID)
	res=1;
 	}
  }
if((res==1)||(res1==1)){
res2=1;}

if((per.ID<0) || (l!=5)){
res3=1;
}
}
while (res3==1 || res2==1);


strcpy(p.nom, gtk_entry_get_text(GTK_ENTRY(entry15)));
strcpy(p.prenom, gtk_entry_get_text(GTK_ENTRY(entry16)));

do {
p.cin = atoi(gtk_entry_get_text(GTK_ENTRY(entry17)));

l=longueurper(p.cin);
}
while ((l!=8) || (p.cin <0) || (ccin==1));

do
{
p.age = atoi(gtk_entry_get_text(GTK_ENTRY(entry18)));
} while ((p.age<0)||(p.age>100));

do
{
strcpy(p.sexe, gtk_entry_get_text(GTK_ENTRY(entry27)));
} while ((strcmp(p.sexe,chsexe1)!=0)&&(strcmp(p.sexe,chsexe2)!=0));



do {
p.numerotelephone = atoi(gtk_entry_get_text(GTK_ENTRY(entry28)));
l=longueurper(p.numerotelephone);
}
while ((p.numerotelephone<0) || (l!=8));

strcpy(p.adresse, gtk_entry_get_text(GTK_ENTRY(entry29)));

do {
strcpy(p.poste, gtk_entry_get_text(GTK_ENTRY(entry30)));
} while ((strcmp(p.poste,chposte1)!=0)&&(strcmp(p.poste,chposte2)!=0));


do {
	p.datedembauche.jour = atoi(gtk_entry_get_text(GTK_ENTRY(entry31)));
	p.datedembauche.mois = atoi(gtk_entry_get_text(GTK_ENTRY(entry32)));
	p.datedembauche.annee = atoi(gtk_entry_get_text(GTK_ENTRY(entry33)));
l2=longueurper(per.datedembauche.annee);

}
while ((p.datedembauche.jour<=0)||(p.datedembauche.mois<=0)||(p.datedembauche.mois>12)||(p.datedembauche.annee<=0)||(l2!=4)||(testj==1));




	ID5 = atoi(gtk_entry_get_text(GTK_ENTRY(entry12)));
	supprimerpersonnel(fichier,ID5);

	enregistrerpersonnel(fichier,&p);

	GtkWidget *window1;
	GtkWidget * window6;
        window6 = lookup_widget(objet_graphique,"window6");
        gtk_widget_hide(window6);
	window1 = create_window1();
    gtk_widget_set_size_request (window1, 400, 600);
	gtk_widget_show (window1);
}


void on_button30_clicked(GtkWidget *objet_graphique, gpointer user_data)
{	
personnel p;
	char fichier[] = "fichierpersonnel.txt";
	int ID;
	int res=0;
	char nom[20];
	GtkWidget *button16;
	GtkWidget *Btnmodifier;
	GtkWidget *entry12;
	GtkWidget *entry13;
	GtkWidget * label48;
	GtkWidget *entry14;
	char Buf1[100]= " "; 
	entry12 = lookup_widget(objet_graphique, "entry12");
	entry13 = lookup_widget(objet_graphique, "entry13");
	label48= lookup_widget(objet_graphique, "label48");
	entry14= lookup_widget(objet_graphique, "entry14");
	strcpy(nom, gtk_entry_get_text(GTK_ENTRY(entry12)));
	ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry13)));

FILE *f;
 
  f=fopen(fichier,"rb");
  if (f!=NULL){
  		while(fread(&p,sizeof(personnel),1,f)!=0 && res==0)
			{
			if((strcmp(p.nom,nom)==0)&&(ID==p.ID))
				{res=1;}
			 }
    		}


	if (res==1)
	{sprintf(Buf1,"Le personnel %s existe \n",nom);
	gtk_label_set_text(GTK_LABEL(label48), Buf1);
	
	Btnmodifier = lookup_widget(objet_graphique,"button16");
	gtk_widget_set_sensitive(GTK_WIDGET(Btnmodifier),TRUE);
		
}
else {sprintf(Buf1,"Le personnel %s n'existe pas \n",nom);
		gtk_label_set_text(GTK_LABEL(label48), Buf1);
}

}




void on_button17_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	GtkWidget * window6;
        window6 = lookup_widget(objet_graphique,"window6");
        gtk_widget_hide(window6);
	window1 = create_window1();
	gtk_widget_set_size_request (window1, 400, 600);
	gtk_widget_show (window1);
}



void on_button18_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	GtkWidget * window7;
        window7 = lookup_widget(objet_graphique,"window7");
        gtk_widget_hide(window7);
	window1 = create_window1();
    gtk_widget_set_size_request (window1, 400, 600);
	gtk_widget_show (window1);
}



void on_button19_clicked(GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *window1;
	GtkWidget * window8;
        window8 = lookup_widget(objet_graphique,"window8");
        gtk_widget_hide(window8);
	window1 = create_window1();
	gtk_widget_set_size_request (window1, 400, 600);
	gtk_widget_show (window1);
}



void
on_button20_clicked  (GtkWidget *objet_graphique, gpointer user_data)
{
	capteur c;
	char ges[]="Liste_capteurs.txt" ;
	GtkWidget *entry19 ;
	GtkWidget *entry20 ;
	entry19 = lookup_widget(objet_graphique, "entry19");
	entry20 = lookup_widget(objet_graphique, "entry20");
	strcpy(c.cap,gtk_entry_get_text(GTK_ENTRY(entry19)));
	strcpy(c.designation,gtk_entry_get_text(GTK_ENTRY(entry20))) ;
	ajoutercapteur(ges,c) ;
	GtkWidget * window11;
	GtkWidget * window9;
        window9 = lookup_widget(objet_graphique,"window9");
        gtk_widget_hide(window9);
	window11 = create_window11();
	gtk_widget_set_size_request (window11, 400, 600);
	gtk_widget_show (window11);
}


void
on_button21_clicked   (GtkWidget *objet_graphique, gpointer    user_data)
{
	GtkWidget * window11;
	GtkWidget * window9;
        window9 = lookup_widget(objet_graphique,"window9");
        gtk_widget_hide(window9);
	window11 = create_window11();
	gtk_widget_set_size_request (window11, 400, 600);
	gtk_widget_show (window11);
}


void
on_button22_clicked    (GtkWidget *objet_graphique, gpointer    user_data)
{
capteur c ;
char nom1[50] ;
char ges[]="Liste_capteurs.txt" ;
GtkWidget *entry21 ;
entry21 = lookup_widget(objet_graphique, "entry21");
strcpy(nom1,gtk_entry_get_text(GTK_ENTRY(entry21)));
supprimercapteur(ges,nom1);
GtkWidget * window11;
	GtkWidget * window10;
        window10 = lookup_widget(objet_graphique,"window10");
        gtk_widget_hide(window10);
	window11 = create_window11();
	gtk_widget_set_size_request (window11, 500, 600);
	gtk_widget_show (window11);
}



void
on_button23_clicked   (GtkWidget   *objet_graphique, gpointer         user_data)
{
	GtkWidget * window11;
	GtkWidget * window10;
        window10 = lookup_widget(objet_graphique,"window10");
        gtk_widget_hide(window10);
	window11 = create_window11();
	gtk_widget_set_size_request (window11, 400, 600);
	gtk_widget_show (window11);
}





void on_button24_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{
GtkWidget * window9;
	GtkWidget * window11;
        window11 = lookup_widget(objet_graphique,"window11");
        gtk_widget_hide(window11);
	window9 = create_window9();
	gtk_widget_set_size_request (window9, 400, 600);
	gtk_widget_show (window9);
}

void on_button25_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{

	GtkWidget * window12;
	GtkWidget * window11;
        window11 = lookup_widget(objet_graphique,"window11");
        gtk_widget_hide(window11);
	window12 = create_window12();
	gtk_widget_set_size_request (window12, 400, 600);
	gtk_widget_show (window12);
	capteur c;
	char ges[]="Liste_capteurs.txt";
	GtkWidget *label51;
	char tmp[1000]="";
	char Buf20[300]="";
	char Buf21[100]= "";
	char Buf22[200]= "";
	FILE *f;
    	f=fopen(ges,"r");
if(f!=NULL){ 
while(fread(&c,sizeof(capteur),1,f)!=0) {
  	sprintf(Buf20,"%s %s  %s %s \n ",Buf21,c.cap,Buf22,c.designation); 
 strcat(tmp,Buf20);
 strcat(tmp,""); 
                  
} 
	label51= lookup_widget(GTK_WIDGET(window12), "label51");
	gtk_label_set_text(GTK_LABEL(label51),tmp);
 }
fclose(f);
}



void on_button26_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{

	GtkWidget * window10;
	GtkWidget * window11;
        window11 = lookup_widget(objet_graphique,"window11");
        gtk_widget_hide(window11);
	window10 = create_window10();
		gtk_widget_set_size_request (window10, 400, 600);
	gtk_widget_show (window10);
}

void on_button27_clicked(GtkWidget *objet_graphique,gpointer  user_data)

{
char ges[]="Liste_capteurs.txt" ;
initcapteur(ges) ;
}

void on_button29_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{
	GtkWidget *window0;
	GtkWidget * window11;
        window11 = lookup_widget(objet_graphique,"window11");
        gtk_widget_hide(window11);
	window0 = create_window0();
	gtk_widget_set_size_request (window0, 400, 600);
	gtk_widget_show (window0);

}


void on_button31_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{
	GtkWidget *window1;
	GtkWidget * window0;
        window0 = lookup_widget(objet_graphique,"window0");
        gtk_widget_hide(window0);
	window1 = create_window1();
	gtk_widget_set_size_request (window1, 400, 600);
	gtk_widget_show (window1);
}


void on_button32_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{
	GtkWidget *window13;
	GtkWidget * window0;
        window0 = lookup_widget(objet_graphique,"window0");
        gtk_widget_hide(window0);
	window13 = create_window13();
	gtk_widget_set_size_request (window13, 400, 600);
	gtk_widget_show (window13);

}


void on_button33_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{
	GtkWidget *window21;
	GtkWidget * window0;
        window0 = lookup_widget(objet_graphique,"window0");
        gtk_widget_hide(window0);
	window21 = create_window21();
	gtk_widget_set_size_request (window21, 1000, 700);
	gtk_widget_show (window21);

}


void on_button34_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{
	GtkWidget *window11;
	GtkWidget * window0;
        window0 = lookup_widget(objet_graphique,"window0");
        gtk_widget_hide(window0);
	window11 = create_window11();
	gtk_widget_set_size_request (window11, 400, 600);
	gtk_widget_show (window11);

}


void on_button35_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{
  gtk_main_quit();
}


void on_button36_clicked(GtkWidget *objet_graphique,gpointer  user_data)
{
GtkWidget * window11;
	GtkWidget * window12;
        window12 = lookup_widget(objet_graphique,"window12");
        gtk_widget_hide(window12);
	window11 = create_window11();
	gtk_widget_set_size_request (window11, 500, 600);
	gtk_widget_show (window11);

}



void
on_button37_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window14;
	GtkWidget * window13;
        window13 = lookup_widget(objet_graphique,"window13");
        gtk_widget_hide(window13);
	window14 = create_window14();
	gtk_widget_set_size_request (window14, 450, 750);
	gtk_widget_show (window14);
}


void
on_button38_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window15;
	GtkWidget * window13;
        window13 = lookup_widget(objet_graphique,"window13");
        gtk_widget_hide(window13);
	window15 = create_window15();
	gtk_widget_set_size_request (window15, 1250, 700);
	gtk_widget_show (window15);
	patient p;
	char fichier[] = "fichierpatient.txt";
	GtkWidget * label77;
	char tmp[100000]="";
	char Buf[1000]="";
	char Buf0[100]= "ID:";
	char Buf1[100]= " nom:";
	char Buf2[100]= " prenom:";
	char Buf3[100]= " cin:";
	char Buf4[100]= " age:";
	char Buf5[100]= " sexe:";
	char Buf6[100]= " num_tel:";
	char Buf7[100]= " adresse:";
	char Buf8[100]= " num_chambre:";
	char Buf9[100]= " num_lit:";
	char Buf10[100]= " nom parrain:";
	char Buf11[100]= " num_tel parrain:";
	char Buf12[100]= " date d'entrée:";
	char Buf13[100]= "/";
	char Buf14[100]= "/";
	char Buf15[100]= " date de sortie: ";
	char Buf16[100]= "/";
	char Buf17[100]= "/";
	FILE*f;

f=fopen(fichier,"rb");
if(f!=NULL)
{
p.ID=0;
strcpy (p.nom," " ) ;
strcpy(p.prenom," ");
p.cin=0;
p.age=0;
strcpy(p.sexe," ");
p.numerotelephone=0;
strcpy(p.adresse," ");
strcpy(p.numchambre," ");
strcpy(p.numlit," ");
strcpy(p.nomparrain," ");
p.numtelparrain=0;
p.dateentree.jour=0;
p.dateentree.mois=0;
p.dateentree.annee=0;
p.datesortie.jour=0;
p.datesortie.mois=0;
p.datesortie.annee=0;
   fread(&p,sizeof(patient),1,f);
   do
  {
   	sprintf(Buf, "%s %d %s %s %s %s %s %ld %s %d %s %s %s %ld %s %s %s %s %s %s %s %s %s %ld %s %d %s %d %s %d %s %d %s %d %s %d ", Buf0, p.ID, Buf1,p.nom, Buf2, p.prenom, Buf3, p.cin, Buf4, p.age, Buf5, p.sexe, Buf6, p.numerotelephone, Buf7,p.adresse, Buf8, p.numchambre, Buf9, p.numlit, Buf10,p.nomparrain,Buf11,p.numtelparrain,Buf12, p.dateentree.jour,Buf13,p.dateentree.mois, Buf14,p.dateentree.annee, Buf15,p.datesortie.jour,Buf16,p.datesortie.mois,Buf17, p.datesortie.annee );
 strcat(tmp,Buf);
strcat(tmp,"\n\n");
 }
   while(((fread(&p,sizeof(patient),1,f))!=0)&&(feof(f)!=1));
	label77= lookup_widget(GTK_WIDGET(window15), "label77");
gtk_label_set_text(GTK_LABEL(label77),tmp);


}

fclose(f);
}



void
on_button39_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window16;
	GtkWidget * window13;
        window13 = lookup_widget(objet_graphique,"window13");
        gtk_widget_hide(window13);
	window16 = create_window16();
	gtk_widget_set_size_request (window16, 400, 600);
	gtk_widget_show (window16);
}


void
on_button40_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window17;
	GtkWidget * window13;
        window13 = lookup_widget(objet_graphique,"window13");
        gtk_widget_hide(window13);
	window17 = create_window17();
	gtk_widget_set_size_request (window17, 400, 650);
	gtk_widget_show (window17);
}


void
on_button41_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window18;
	GtkWidget * window13;
        window13 = lookup_widget(objet_graphique,"window13");
        gtk_widget_hide(window13);
	window18 = create_window18();
	gtk_widget_set_size_request (window18, 400, 680);
	gtk_widget_show (window18);
}


void
on_button42_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window19;
	GtkWidget * window13;
        window13 = lookup_widget(objet_graphique,"window13");
        gtk_widget_hide(window13);
	window19 = create_window19();
	gtk_widget_show (window19);
	char fichier[] = "fichierpatient.txt";
	char Buf0[100];
	GtkWidget * label117;
	initpersonnels(fichier);
	label117= lookup_widget(objet_graphique, "label117");
	sprintf (Buf0, "Patients initialisés");
	gtk_label_set_text(GTK_LABEL(label117), Buf0);


}


void
on_button43_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window20;
	GtkWidget * window13;
        window13 = lookup_widget(objet_graphique,"window13");
        gtk_widget_hide(window13);
	window20 = create_window20();
	gtk_widget_set_size_request (window20, 1250, 700);
	gtk_widget_show (window20);
	patient p;
	char tmp3[] = "tmp3.txt";
	GtkWidget * label121;

	char tmp[100000]="";
	char Buf[1500]="";
	char Buf0[100]= "ID:";
	char Buf1[100]= " nom:";
	char Buf2[100]= " prenom:";
	char Buf3[100]= " cin:";
	char Buf4[100]= " age:";
	char Buf5[100]= " sexe:";
	char Buf6[100]= " num_tel:";
	char Buf7[100]= " adresse:";
	char Buf8[100]= " num_chambre:";
	char Buf9[100]= " num_lit: ";
	char Buf10[100]= " nom parrain:";
	char Buf11[100]= " num_tel parrain:";
	char Buf12[100]= " date d'entrée:";
	char Buf13[100]= "/";
	char Buf14[100]= "/";
	char Buf15[100]= " date de sortie:";
	char Buf16[100]= "/";
	char Buf17[100]= "/";
	FILE*f;

f=fopen(tmp3,"rb");
if(f!=NULL)
{
p.ID=0;
strcpy (p.nom," " ) ;
strcpy(p.prenom," ");
p.cin=0;
p.age=0;
strcpy(p.sexe," ");
p.numerotelephone=0;
strcpy(p.adresse," ");
strcpy(p.numchambre," ");
strcpy(p.numlit," ");
strcpy(p.nomparrain," ");
p.numtelparrain=0;
p.dateentree.jour=0;
p.dateentree.mois=0;
p.dateentree.annee=0;
p.datesortie.jour=0;
p.datesortie.mois=0;
p.datesortie.annee=0;
   fread(&p,sizeof(patient),1,f);
   do
  {
   	sprintf(Buf, "%s %d %s %s %s %s %s %ld %s %d %s %s %s %ld %s %s %s %s %s %s %s %s %s %ld %s %d %s %d %s %d %s %d %s %d %s %d ", Buf0, p.ID, Buf1,p.nom, Buf2, p.prenom, Buf3, p.cin, Buf4, p.age, Buf5, p.sexe, Buf6, p.numerotelephone, Buf7,p.adresse, Buf8, p.numchambre, Buf9, p.numlit, Buf10,p.nomparrain,Buf11,p.numtelparrain,Buf12, p.dateentree.jour,Buf13,p.dateentree.mois, Buf14,p.dateentree.annee, Buf15,p.datesortie.jour,Buf16,p.datesortie.mois,Buf17, p.datesortie.annee );
 strcat(tmp,Buf);
strcat(tmp,"\n\n");
 }
   while(((fread(&p,sizeof(patient),1,f))!=0)&&(feof(f)!=1));
	label121= lookup_widget(GTK_WIDGET(window20), "label121");
gtk_label_set_text(GTK_LABEL(label121),tmp);
}

fclose(f);
}



void
on_button44_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window0;
	GtkWidget * window13;
        window13 = lookup_widget(objet_graphique,"window13");
        gtk_widget_hide(window13);
	window0 = create_window0();
	gtk_widget_set_size_request (window0, 400, 600);
	gtk_widget_show (window0);
}


void
on_button45_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	patient p;
	char fichier[] = "fichierpatient.txt";
	FILE *y;
	FILE *f;
	int ID;
	int cin;
	int age;
	int numero,numero2;
	
	char Buf1[20]= " ";
	char Buf2[20]= " ";
	char Buf3[20]= " ";
	char Buf4[20]= " ";
	char Buf5[20]= " ";
	char Buf6[20]= " ";
	char tmp3[] = "tmp3.txt";
	int ccin=0;
	int l=0;
	int c=0;
	int eannee,sannee,emois,smois,ejour,sjour;


	int res,res1,res2,res3;
	int rescin=0;
	int res4=0,res5=0,res6=0,res7=0,res8=0,res9=0,res10=0;
	GtkWidget *entry41;
	GtkWidget *entry42;
	GtkWidget *entry43;
	GtkWidget *entry44;
	GtkWidget *entry45;
	GtkWidget *entry47;
	GtkWidget *entry48;
	GtkWidget *entry49;
	GtkWidget *entry50;
	GtkWidget *entry51;
	GtkWidget *entry52;
	GtkWidget * label159;
	GtkWidget * label160;
	GtkWidget * label161;
	GtkWidget * label162;
	GtkWidget * label163;
	GtkWidget * label158;

	GtkWidget *combobox5;
	GtkCalendar *calendar3;
	GtkCalendar *calendar4;

	label159= lookup_widget(objet_graphique, "label159");
	label160= lookup_widget(objet_graphique, "label160");
	label161= lookup_widget(objet_graphique, "label161");
	label162= lookup_widget(objet_graphique, "label162");
	label163= lookup_widget(objet_graphique, "label163");
	label158= lookup_widget(objet_graphique, "label158");
	entry41 = lookup_widget(objet_graphique, "entry41");
	entry42 = lookup_widget(objet_graphique, "entry42");
	entry43 = lookup_widget(objet_graphique, "entry43");
	entry44 = lookup_widget(objet_graphique, "entry44");
	entry45 = lookup_widget(objet_graphique, "entry45");
	entry47 = lookup_widget(objet_graphique, "entry47");
	entry48 = lookup_widget(objet_graphique, "entry48");
	entry49 = lookup_widget(objet_graphique, "entry49");
	entry50 = lookup_widget(objet_graphique, "entry50");
	entry51= lookup_widget(objet_graphique, "entry51");
	entry52= lookup_widget(objet_graphique, "entry52");
	combobox5 = lookup_widget(objet_graphique, "combobox5");
	calendar3 = lookup_widget(objet_graphique, "calendar3");
	calendar4 = lookup_widget(objet_graphique, "calendar4");
	sprintf(Buf1,"");
	gtk_label_set_text(GTK_LABEL(label158), Buf1);
	sprintf(Buf2,"");
	gtk_label_set_text(GTK_LABEL(label159), Buf2);
	sprintf(Buf3,"");
	gtk_label_set_text(GTK_LABEL(label160), Buf3);
	sprintf(Buf4,"");
	gtk_label_set_text(GTK_LABEL(label161), Buf4);
	sprintf(Buf5,"");
	gtk_label_set_text(GTK_LABEL(label162), Buf5);
	sprintf(Buf6,"");
	gtk_label_set_text(GTK_LABEL(label163), Buf6);

res=0;
res1=0;
res2=0;
res3=0;
ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry42)));
l=longueurpat(ID);
y=fopen("tmp3.txt","a+");
	if (y!=NULL){
  		while((fread(&p,sizeof(patient),1,y)!=0) && (res1==0))
		{
		if(ID==p.ID)
		res1=1;
 		}
	}
f=fopen(fichier,"rb");
  if (f!=NULL){
  while((fread(&p,sizeof(patient),1,f)!=0) && (res==0))
	{
	if(ID==p.ID)
	res=1;
 	}
  }if((ID<0) || (l!=5)){
res3=1;
}
if((res==0)&&(res1==0)&&(res3==0)){
res2=1;}

cin = atoi(gtk_entry_get_text(GTK_ENTRY(entry45)));

  f=fopen("fichierpatient","a");
  if (f!=NULL)
	{
         while((fread(&p,sizeof(patient),1,f)!=0) && (res5==0))
 	    {
	      if(cin==p.cin)
	       {res5=1;}
 	    }
 	}
  y=fopen("tmp3","a");
  if ((y!=NULL) )

	{
         while((fread(&p,sizeof(patient),1,y)!=0) && (res6==0))
 	    {
	      if(cin==p.cin)
	       {res6=1;}
 	    }
 	}
if( (res5==0) && (res6==0))
{res4=1;}
l=longueurpat(cin);
if ((res4==1)&& (l==8))
{rescin=1;}

age = atoi(gtk_entry_get_text(GTK_ENTRY(entry44)));
if ((age>0)&&(age<110))
{
res7=1;
}

gtk_calendar_get_date (calendar3,&eannee,&emois,&ejour);
emois=emois+1;
gtk_calendar_get_date (calendar4,&sannee,&smois,&sjour);
smois=smois+1;

if(eannee<sannee)
{ res10=1;}
else if (eannee==sannee)
	{if (emois<smois)
		{res10=1;}
		else if (emois==smois)
			{if (ejour<sjour)
				{res10=1;}
			}
	}

numero = atoi(gtk_entry_get_text(GTK_ENTRY(entry47)));
l=longueurpat(numero);
if(l==8){
res8=1;}



numero2 = atoi(gtk_entry_get_text(GTK_ENTRY(entry52)));
l=longueurpat(numero2);
if(l==8){
res9=1;}




if(res2==0){

	sprintf(Buf1,"ERREUR");
	gtk_label_set_text(GTK_LABEL(label158), Buf1);
}
if(rescin==0){

	sprintf(Buf2,"ERREUR");
	gtk_label_set_text(GTK_LABEL(label159), Buf2);
}
if(res7==0){

	sprintf(Buf3,"ERREUR");
	gtk_label_set_text(GTK_LABEL(label160), Buf3);
}
if(res8==0){

	sprintf(Buf4,"ERREUR");
	gtk_label_set_text(GTK_LABEL(label161), Buf4);
}
if(res9==0){

	sprintf(Buf5,"ERREUR");
	gtk_label_set_text(GTK_LABEL(label162), Buf5);
}

if(res10==0){

	sprintf(Buf6,"ERREUR");
	gtk_label_set_text(GTK_LABEL(label163), Buf6);
}

if((res2==1)&&(rescin==1)&&(res7==1)&&(res8==1)&&(res9==1)&&(res10==1)){


p.ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry42)));
strcpy(p.nom, gtk_entry_get_text(GTK_ENTRY(entry41)));
strcpy(p.prenom, gtk_entry_get_text(GTK_ENTRY(entry43)));
p.cin = atoi(gtk_entry_get_text(GTK_ENTRY(entry45)));
p.age = atoi(gtk_entry_get_text(GTK_ENTRY(entry44)));
p.numerotelephone = atoi(gtk_entry_get_text(GTK_ENTRY(entry47)));
strcpy(p.adresse, gtk_entry_get_text(GTK_ENTRY(entry48)));
strcpy(p.numchambre, gtk_entry_get_text(GTK_ENTRY(entry49)));
strcpy(p.numlit, gtk_entry_get_text(GTK_ENTRY(entry50)));
strcpy(p.nomparrain, gtk_entry_get_text(GTK_ENTRY(entry51)));
p.numtelparrain = atoi(gtk_entry_get_text(GTK_ENTRY(entry52)));
strcpy(p.sexe, gtk_combo_box_get_active_text(GTK_COMBO_BOX(combobox5)));
gtk_calendar_get_date (calendar3,&p.dateentree.annee,&p.dateentree.mois,&p.dateentree.jour);
p.dateentree.mois= p.dateentree.mois+1;
gtk_calendar_get_date (calendar4,&p.datesortie.annee,&p.datesortie.mois,&p.datesortie.jour);
p.datesortie.mois= p.datesortie.mois+1;



	enregistrerpatient(fichier,&p);

	GtkWidget *window13;
	GtkWidget * window14;
        window14 = lookup_widget(objet_graphique,"window14");
        gtk_widget_hide(window14);
	window13 = create_window13();
	gtk_widget_set_size_request (window13, 400, 600);
	gtk_widget_show (window13);
}
}

void
on_button46_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window13;
	GtkWidget * window14;
        window14 = lookup_widget(objet_graphique,"window14");
        gtk_widget_hide(window14);
	window13 = create_window13();
	gtk_widget_set_size_request (window13, 400, 600);
	gtk_widget_show (window13);
}


void
on_button47_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window13;
	GtkWidget * window15;
        window15 = lookup_widget(objet_graphique,"window15");
        gtk_widget_hide(window15);
	window13 = create_window13();
	gtk_widget_set_size_request (window13, 400, 600);
	gtk_widget_show (window13);
}


void
on_button48_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
patient p;
	char fichier[] = "fichierpatient.txt";
	int ID;
	char nom[20];
	int res=0;
	char Buf20[1500]="";
	char Buf0[100]= "ID:";
	char Buf1[100]= " nom:";
	char Buf2[100]= " prenom:";
	char Buf3[100]= " cin:";
	char Buf4[100]= " age:";
	char Buf5[100]= " sexe:";
	char Buf6[100]= " num_tel:";
	char Buf7[100]= " adresse:";
	char Buf8[100]= " num_chambre:";
	char Buf9[100]= " num_lit:";
	char Buf10[100]= " nom parrain:";
	char Buf11[100]= " num_tel parrain:";
	char Buf12[100]= " date d'entrée:";
	char Buf13[100]= "/";
	char Buf14[100]= "/";
	char Buf15[100]= " date de sortie:";
	char Buf16[100]= "/";
	char Buf17[100]= "/";
	char Buf18[100]= " ";
	FILE *f;

	GtkWidget *entry60;
	GtkWidget *entry59;
	GtkWidget * label85;
	GtkWidget * label86;
	entry59 = lookup_widget(objet_graphique, "entry59");
	entry60 = lookup_widget(objet_graphique, "entry60");
	label85= lookup_widget(objet_graphique, "label85");
	label86= lookup_widget(objet_graphique, "label86");
	strcpy(nom, gtk_entry_get_text(GTK_ENTRY(entry59)));
	ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry60)));


p.ID=0;
strcpy (p.nom," " ) ;
strcpy(p.prenom," ");
p.cin=0;
p.age=0;
strcpy(p.sexe," ");
p.numerotelephone=0;
strcpy(p.adresse," ");
strcpy(p.numchambre," ");
strcpy(p.numlit," ");
strcpy(p.nomparrain," ");
p.numtelparrain=0;
p.dateentree.jour=0;
p.dateentree.mois=0;
p.dateentree.annee=0;
p.datesortie.jour=0;
p.datesortie.mois=0;
p.datesortie.annee=0;
 
  f=fopen(fichier,"rb");
  if (f!=NULL){



  		while(fread(&p,sizeof(patient),1,f)!=0 && res==0)
			{
			if((strcmp(p.nom,nom)==0)&&(ID==p.ID))
				{res=1;
				break;}
			 }
    		}

if (res==1)
	{sprintf(Buf18,"Le patient %s existe \n",nom);
	gtk_label_set_text(GTK_LABEL(label85), Buf18);

  	sprintf(Buf20, "%s %d %s %s %s %s %s %ld \n %s %d %s %s %s %ld %s %s \n %s %s %s %s %s %s %s %ld \n %s %d %s %d %s %d %s %d %s %d %s %d ", Buf0, p.ID, Buf1,p.nom, Buf2, p.prenom, Buf3, p.cin, Buf4, p.age, Buf5, p.sexe, Buf6, p.numerotelephone, Buf7,p.adresse, Buf8, p.numchambre, Buf9, p.numlit, Buf10,p.nomparrain,Buf11,p.numtelparrain,Buf12, p.dateentree.jour,Buf13,p.dateentree.mois, Buf14,p.dateentree.annee, Buf15,p.datesortie.jour,Buf16,p.datesortie.mois,Buf17, p.datesortie.annee );

label86= lookup_widget(objet_graphique, "label86");
gtk_label_set_text(GTK_LABEL(label86), Buf20);
fclose(f);
	}
	else {sprintf(Buf18,"Le patient %s n'existe pas \n",nom);
		gtk_label_set_text(GTK_LABEL(label85), Buf18);}
}


void
on_button49_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window13;
	GtkWidget * window16;
        window16 = lookup_widget(objet_graphique,"window16");
        gtk_widget_hide(window16);
	window13 = create_window13();
	gtk_widget_set_size_request (window13, 400, 600);
	gtk_widget_show (window13);
}


void
on_button50_clicked (GtkWidget *objet_graphique, gpointer user_data)
{
	GtkWidget *entry61;
	GtkWidget * label164;
	GtkWidget *window13;
	GtkWidget * window17;
	
	patient p;
	int ID;
	char fichier[] = "fichierpatient.txt";
	char Buf0[1000];
	int res=0;
	entry61 = lookup_widget(objet_graphique, "entry61");
	ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry61)));
	
FILE *f;
 
  f=fopen(fichier,"rb");
  if (f!=NULL){
  		while((fread(&p,sizeof(patient),1,f)!=0) && (res==0))
			{
			if(ID==p.ID)
				{res=1;}
			 }
    		}
fclose(f);

	if (res==0)
{
	label164= lookup_widget(objet_graphique, "label164");
	sprintf(Buf0,"Ce personnel n'existe pas \n");
	gtk_label_set_text(GTK_LABEL(label164), Buf0);}

else {
	supprimerpatient(fichier,ID);
        window17 = lookup_widget(objet_graphique,"window17");
        gtk_widget_hide(window17);
	window13 = create_window13();
	gtk_widget_set_size_request (window13, 900, 600);
	gtk_widget_show (window13);
}
}


void
on_button51_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window13;
	GtkWidget * window17;
        window17 = lookup_widget(objet_graphique,"window17");
        gtk_widget_hide(window17);
	window13 = create_window13();
	gtk_widget_set_size_request (window13, 400, 600);
	gtk_widget_show (window13);
}


void
on_button52_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	patient p;
	char fichier[] = "fichierpatient.txt";
	int ID;
	int res=0;
	char nom[20];
	GtkWidget *button55;
	GtkWidget *Btnmodifier;
	GtkWidget *entry62;
	GtkWidget *entry63;
	GtkWidget * label100;
	char Buf1[100]= " "; 
	entry62 = lookup_widget(objet_graphique, "entry62");
	entry63 = lookup_widget(objet_graphique, "entry63");
	label100= lookup_widget(objet_graphique, "label100");
	strcpy(nom, gtk_entry_get_text(GTK_ENTRY(entry62)));
	ID = atoi(gtk_entry_get_text(GTK_ENTRY(entry63)));

FILE *f;
 
  f=fopen(fichier,"rb");
  if (f!=NULL){
  		while(fread(&p,sizeof(patient),1,f)!=0 && res==0)
			{
			if((strcmp(p.nom,nom)==0)&&(ID==p.ID))
				{res=1;}
			 }
    		}


	if (res==1)
	{sprintf(Buf1,"Le patient %s existe \n",nom);
	gtk_label_set_text(GTK_LABEL(label100), Buf1);
	
	Btnmodifier = lookup_widget(objet_graphique,"button55");
	gtk_widget_set_sensitive(GTK_WIDGET(Btnmodifier),TRUE);
		
}
else {sprintf(Buf1,"Le personnel %s n'existe pas \n",nom);
		gtk_label_set_text(GTK_LABEL(label100), Buf1);
}

}




void
on_button55_clicked (GtkWidget *objet_graphique,gpointer user_data)
{

}


void
on_button56_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window13;
	GtkWidget * window18;
        window18 = lookup_widget(objet_graphique,"window18");
        gtk_widget_hide(window18);
	window13 = create_window13();
	gtk_widget_set_size_request (window13, 400, 600);
	gtk_widget_show (window13);
}


void
on_button53_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window13;
	GtkWidget * window19;
        window19 = lookup_widget(objet_graphique,"window19");
        gtk_widget_hide(window19);
	window13 = create_window13();
	gtk_widget_set_size_request (window13, 400, 600);
	gtk_widget_show (window13);
}


void
on_button54_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window13;
	GtkWidget * window20;
        window20 = lookup_widget(objet_graphique,"window20");
        gtk_widget_hide(window20);
	window13 = create_window13();
	gtk_widget_set_size_request (window13, 400, 600);
	gtk_widget_show (window13);
}


void
on_button57_clicked (GtkWidget *objet_graphique,gpointer user_data)
{
	GtkWidget *window0;
	GtkWidget * window21;
        window21 = lookup_widget(objet_graphique,"window21");
        gtk_widget_hide(window21);
	window0 = create_window0();
	gtk_widget_set_size_request (window0, 400, 600);
	gtk_widget_show (window0);
}


void
on_button58_clicked (GtkWidget *objet_graphique, gpointer user_data)
{       char ref[]="chemin_capteurs.txt"; 
        

         GtkWidget *entry83;
        entry83=lookup_widget(objet_graphique,"entry83"); 
        long ID=atol(gtk_entry_get_text(GTK_ENTRY(entry83)));
         

        GtkWidget *window22;
	GtkWidget * window21;
        window21 = lookup_widget(objet_graphique,"window21");
        gtk_widget_hide(window21);
	window22 = create_window22();
	gtk_widget_set_size_request (window22, 400, 600);
	gtk_widget_show (window22);

        char parcours[300];
      
        strcpy(parcours,analyse(ref,ID));
        
        char tmp100[100000]="";
        char Buf100[50]="";
        char Buf101[50]="";
        GtkWidget * label144;
        sprintf(Buf100,"%s %s \n\n",Buf101,parcours);
        strcat(tmp100,Buf100);
        strcat(tmp100,"\n\n");
        label144 = lookup_widget(GTK_WIDGET(window22),"label144");
        
        gtk_label_set_text(GTK_LABEL(label144),tmp100); 
    
   
	
}


void
on_button59_clicked  (GtkWidget *objet_graphique, gpointer user_data)
{     


	
}



void on_button63_clicked (GtkWidget *objet_graphique, gpointer user_data)
{   
      
        GtkWidget *window21;
	GtkWidget * window22;
        window22 = lookup_widget(objet_graphique,"window22");
        gtk_widget_hide(window22);
	window21 = create_window21();
	gtk_widget_show (window21);

}






void
on_button64_clicked  (GtkButton  *objet_graphique,gpointer user_data)
                                        
{
	GtkWidget *window25;
	GtkWidget * window11;
        window11 = lookup_widget(objet_graphique,"window11");
        gtk_widget_hide(window11);
	window25 = create_window25();
	gtk_widget_set_size_request (window25, 500, 600);
	gtk_widget_show (window25);

}


void
on_button66_clicked                    (GtkButton  *objet_graphique,
                                        gpointer         user_data)
{
	GtkWidget *window11;
	GtkWidget * window25;
        window25 = lookup_widget(objet_graphique,"window25");
        gtk_widget_hide(window25);
	window11 = create_window11();
	gtk_widget_set_size_request (window11, 500, 600);
	gtk_widget_show (window11);
}


void
on_button65_clicked                    (GtkButton       *objet_graphique,
                                        gpointer         user_data)
{

	char ch[78];
	char ref[]="chemin_capteurs.txt";
	GtkWidget *entry86;
	GtkWidget *window11;
	GtkWidget * window25;
	entry86 = lookup_widget(objet_graphique, "entry86");
	strcpy(ch,gtk_entry_get_text(GTK_ENTRY(entry86)));
	FILE *f;
  	f=fopen(ref,"w");
	fprintf(f,"%s",ch);
	fclose(f);
	window25 = lookup_widget(objet_graphique,"window25");
        gtk_widget_hide(window25);
	window11 = create_window11();
	gtk_widget_set_size_request (window11, 400, 600);
	gtk_widget_show (window11);
	

}


void on_button60_clicked(GtkWidget *objet_graphique,gpointer user_data)
{float a,b;
 //int n=0;
 //int trouve=0;
 char password[]="esprit";
 char userid[]="nesrine";
 char id[100];
 char pass[100];

  	GtkWidget *entry84;
  	GtkWidget *entry85;
	GtkWidget *window24;
	GtkWidget *window0;
	GtkWidget *window23;

entry84=lookup_widget(objet_graphique,"entry84");
entry85=lookup_widget(objet_graphique,"entry85");
/*do
{*/

         strcpy(id,gtk_entry_get_text(GTK_ENTRY(entry84)));
    	 strcpy(pass,gtk_entry_get_text(GTK_ENTRY(entry85)));

          a=strcmp(id,userid);
          b=strcmp(pass,password);

        if ((a==0) && (b==0))
        {
	  GtkWidget *window0;
	  GtkWidget *window23;
         window23=lookup_widget(objet_graphique,"window23");
         gtk_widget_hide(window23);
         window0=create_window0();
	gtk_widget_set_size_request (window0, 400, 600);
         gtk_widget_show(window0);
         //trouve=1;

        }

     else
       { window23=lookup_widget(objet_graphique,"window23");
         gtk_widget_hide(window23);
         window24=create_window24();
         gtk_widget_show(window24);}
         //n++;
/*if(n<3)
      {break;}*/
       }


/*}while((trouve==0 )&& (n<4));

         if(n==3)
         {
            window24=lookup_widget(objet_graphique,"window24");
            gtk_widget_hide(window24);

         }*/

void on_button61_clicked(GtkWidget *objet_graphique,gpointer user_data)
{
   GtkWidget *window23;
   GtkWidget *window24;
   window24=lookup_widget(objet_graphique,"window24");
   gtk_widget_hide(window24);
   window23=create_window23();
   gtk_widget_show(window23);


}



void
on_button67_clicked                    (GtkButton       *objet_graphique,
                                        gpointer         user_data)
{
	char ch[78];
	char ref[]="chemin_capteurs.txt";
	GtkWidget *label151;
	char tmp[1000]="";
	char Buf20[300]="";
	char Buf21[300]="";
	FILE *f;
    	f=fopen(ref,"rb");
if(f!=NULL){ 
while(fread(&ch,sizeof(char),1,f)!=0) {
  	sprintf(Buf20,"%s %s",Buf21,ch); 
 strcat(tmp,Buf20); 
                  
} 
	label151= lookup_widget(objet_graphique, "label151");
	gtk_label_set_text(GTK_LABEL(label151),tmp);
 }
fclose(f);
}





